package com.xiaobai.handler;

import com.baomidou.mybatisplus.core.handlers.MetaObjectHandler;
import org.apache.ibatis.reflection.MetaObject;
import org.springframework.stereotype.Component;

import java.util.Date;

@Component
public class MyMetaObjectHandler implements MetaObjectHandler {

    @Override
    public void insertFill(MetaObject metaObject) {

        /**
         * 1.strictInsertFill和strictUpdateFill的区别
         *   insert在不存在时会插入(存在时,不会插入),update在存在时会修改(不存在时不会修改)
         * 2.参数: 对象 属性名 value value类型
         */

        this.strictInsertFill(metaObject, "createTime",
                Date::new, Date.class);
        this.strictInsertFill(metaObject, "updateTime",
                Date::new, Date.class);

    }

    @Override
    public void updateFill(MetaObject metaObject) {

        this.strictUpdateFill(metaObject, "updateTime",
                Date::new, Date.class);


    }

}
